package com.ivan.security.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Ivan
 * @Title: HelloController
 * @date 2021/8/2410:46
 */
@RestController
public class HelloController {

    @GetMapping("/")
    public String index() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return authentication.getPrincipal().toString();
    }

    @GetMapping("/admin/hello")
    public String admin() {
        return "hello admin!" + SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
    }

    @GetMapping("/dba/hello")
    public String dba() {
        return "hello dba!" + SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
    }

    @GetMapping("/user/hello")
    public String user() {
        return "hello user!" + SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
    }

}
